begintownscript;

variables;
short desccave,readbook;

body;

beginstate 0;

	if(get_flag(2,1) < 70){
		force_instant_terrain_redraw();
		reset_dialog();
		add_dialog_str(0,"The caves down here are particularly dark.  Light from above glows dimly, but you won't be able to see much further in without a source of light.",0);
		add_dialog_str(1,"You cannot begin to fathom what sort of structure this is, or what sort of tribe once inhabited it.",0);
		add_dialog_str(2,"You see a statue in front of you.  It appears to be extremely well made, although bizarrely so.  It is running towards the stairs in a panic, and like those around it; it seems to be heading from the eastern hallways.",0);
		add_dialog_str(3,"Its face is wrenched into a position of terror and awe.  Why somebody would make something like this is totally beyond you, but it probably has something to do with the thing to the east that it seems to be running from.",0);
		add_dialog_str(4,"Hopefully, you will find the Aquos Gem inside without any troubles.  Of course, that all depends on avoiding what is apparently to the east.",0);
		desccave = run_dialog(1);
		set_flag(2,1,70);
	}

	add_char_to_group(7,1);
	add_char_to_group(8,1);
	add_char_to_group(9,1);
	add_char_to_group(10,1);
	add_char_to_group(11,1);
	add_char_to_group(12,1);
	add_char_to_group(13,1);
	add_char_to_group(14,1);
	add_char_to_group(15,1);
	add_char_to_group(16,1);
	add_char_to_group(17,1);
	add_char_to_group(18,1);
	add_char_to_group(19,1);
	add_char_to_group(20,1);
	add_char_to_group(21,1);

break;

beginstate 1;
break;

beginstate START_STATE;
break;

beginstate 10;


	if(is_combat() == 1){
		print_str_color("Can't leave town in combat mode.",1);
		block_entry(1);
		end();
	}

	if(remove_char_from_party(319) == 1){
		message_dialog("_Yahoo!_ shouts the goblin.  _Me's free again!  Yes-yes-yes!!!  See ya, big strongarm man warrior!_","With that, he races as fast as his spindly legs can take him up the stairs and out of sight.");
		award_party_xp(1000,100);
	}

	move_to_new_town(2,23,6);

break;

beginstate 11;

	if(get_flag(7,1) == 0){
		set_attitude(22,10);
		set_attitude(23,10);
		set_attitude(24,10);
	}

break;

beginstate 12;

	if(get_flag(9,1) == 0){
		message_dialog("Eew!  This entire room is filled with large, metal cylinders filled with and occasionally leaking out noxious, green goop.","What purpose does this place have?  Who made this room, and why?");
		set_flag(9,1,1);
	}
break;

beginstate 13;

	if(get_flag(10,1) == 0){
		message_dialog("This room is an enigma to you.  There are metal cylinders lining the walls, and what appears to have been a fire of sorts on a raised platform.","There is a room with standing water, and the windows are broken.  There is also a wheel without any reasonable way to turn it that you can see.  The purpose of this room is beyond you at this point.");
		set_flag(10,1,1);
	}

break;

beginstate 14;

	if(get_flag(11,1) == 0){
		message_dialog("As you enter this room, you here a low whining or grumbling noise.  You also smell trash and sweat.  Sure enough, a goblin is down here.","He seems quite afraid for his life, and makes no move to attack you.  He must have gotten quite lucky to get into this room safely, although he likely cannot leave.");
		set_flag(11,1,1);
	}

break;

beginstate 25;

	if(get_flag(8,1) == 0){
		message_dialog("The chest here is mostly empty, save for a few rotten clothing articles and a metallic key similar to the one you received from the goblin chief's corpse.","You pick it up- you never know when it will come in handy.");
		change_spec_item(2,1);
		set_flag(8,1,1);
	}

break;

beginstate 26;

	reset_dialog_preset_options(7);
	readbook = run_dialog(0);
	if(readbook == 1){
		end();
	}
	else{
		reset_dialog();
		add_dialog_str(0,"It's in your language!  This tribe must have been here very recently, and must have been similar to your own in some way.",0);
		add_dialog_str(1,"At any rate, the book is still mostly intact.  Since you don't feel like reading the entire text, you flip to its lattermost pages.",0);
		add_dialog_str(2,"Imperial Research Facility _PROPHANAI_ Research Log, Day 775",0);
		add_dialog_str(3,"Things go well.  Our project for a self-sustaining, invincible construct entitled _Lyfan_ is nearing completion.  The prototype will be activated two days from now.",0);
		add_dialog_str(4,"The power source works well.  The idea of bringing in toxins to fuel a fire used to boil water, generating steam and turning a turbine was also genius.",0);
		add_dialog_str(5,"We are expecting mass shipments of highly flammable substances from the Krizsan province tomorrow.",0);
		add_dialog_choice(0,"Close the book.");
		add_dialog_choice(1,"Keep reading.");
		readbook = run_dialog(1);
		if(readbook == 1){
			end();
		}
		reset_dialog();
		add_dialog_str(0,"Imperial Research Facility _PROPHANAI_ Research Log, Day 776",0);
		add_dialog_str(1,"We received the shipments from Krizsan today.  The Imperial representative warned us half-assedly about some sort of caveat to this substance's normally inert nature, but was rather vague about it.",0);
		add_dialog_str(2,"At any rate, we have the magical stones set in accordance to imbue Lyfan with docility when we create him.  Admittedly, I know less about this process than I should.",0);
		add_dialog_str(3,"Nevertheless, I have been re-assured by the magi leading the project that many precautions have been taken to assure that Lyfan will turn out as intended.",0);
		add_dialog_str(4,"Tomorrow, the steam power will give life to our automaton, my name will rise into fame and the chronicles of history, and almost three years here at Prophanai will have payed off.",0);
		add_dialog_str(5,"[The book ends here, there are no more entries.]",0);
		readbook = run_dialog(1);
	}

break;

beginstate 27;

	if(get_flag(2,1) < 75){
		large_draw_pic_dialog(404,"The Aquos Gem!");
		message_dialog("The chest is mostly empty, except for cobwebs and the holiest of artifacts to members of your tribe.","You anxiously pick up the stone and pocket it.  Now, you can leave this wretched place and return to your village.");
		change_spec_item(10,1);
		set_flag(2,1,75);
	}

break;